package model;

import java.util.HashMap;

/**
 * 
 * @author Gaëtan Chapelon, Thomas Donzelle, Elias Kani, Ryiadh Benammar
 * This class give us tools to manipulate our strings
 *
 */
public class Tools {
private static HashMap<String,Integer> letterFrequency=new HashMap<String,Integer>(){
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	{
		put("a", 14);
		put("b", 3);
		put("c", 7);
		put("d", 6);
		put("e", 20);
		put("f", 2);
		put("g", 5);
		put("h", 4);
		put("i", 15);
		put("j", 0);
		put("k", 2);
		put("l", 9);
		put("m", 5);
		put("n", 13);
		put("o", 10);
		put("p", 5);
		put("q", 0);
		put("r", 13);
		put("s", 14);
		put("t", 12);
		put("u", 5);
		put("v", 2);
		put("w", 1);
		put("x", 0);
		put("y", 3);
		put("z", 1);
	}
};

/**
 * 
 * @param A string S
 * @param A frequency f
 * @return The String S simplified
 */
public static String SimplifyByFreq(String s, int f){
	
	for(java.util.Map.Entry<String, Integer> entry : letterFrequency.entrySet()) {
	    String key = entry.getKey();
	    if (entry.getValue()<f){
	    	s = s.replace(key, "");
	    }
	}
	
	return s;
	
}

/**
 * 
 * @param A string S
 * @param A frequency f
 * @return The String S simplified
 */
public static String SimplifyAlea(String s, int f){
	int sLen = s.length();
	String result= new String();
	String s1, s2;
	int r;
	for(int i=0; i<sLen;i++) {
		r = (int)(Math.random()*100.0);
	    if (r<f){
	    	result += s.substring(i, i+1);
	    }
	}
	
	return result;
	
}

/**
 * 
 * @param A string S
 * @param A string b
 * @return A array of strings
 */
public static String[] OrderStrings(String a, String b){
	String[] strings = new String[2];
	String c;
	if (a.length() >= b.length()) {
        c = a;
        a = b;
        b = c;
    }
	
	strings[0]=a;
	strings[1]=b;
	
	return strings;
	
}
}
